package Ioperate;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * @Author liangzai
 * @Description:
 */
public class BrowwedBook implements Ioperate{
    public void work(BookList bookList){
        Scanner scanner = new Scanner(System.in);
        int count = bookList.getSize();

        System.out.println("请输入要借阅的书名：");
        String name = scanner.nextLine();

        for (int i = 0; i < count; i++) {
            Book book = bookList.getBooks(i);
            if(book.getName().equals(name)){
                if(book.isaBoolean()==false){
                    book.setaBoolean(true);
                    System.out.println();
                    return ;
                }else{
                    System.out.println("此书已借出！");
                    System.out.println();
                    return ;
                }
            }
            if(i==count) {
                System.out.println("此书不存在！");
                System.out.println();
            }
        }
    }
}
